cmake_minimum_required(VERSION 3.1)
project(detex LANGUAGES C)

set(SOURCE_FILES
   "bptc-tables.c"
    "bits.c"
    "clamp.c"
    "convert.c"
    "dds.c"
    "decompress-bc.c"
    "decompress-bptc.c"
    "decompress-bptc-float.c"
    "decompress-etc.c"
    "decompress-eac.c"
    "decompress-rgtc.c"
    "division-tables.c"
    "file-info.c"
    "half-float.c"
    "hdr.c"
    "ktx.c"
    "misc.c"
    "raw.c"
    "texture.c")

if(CMAKE_BUILD_TYPE STREQUAL Release)
    set(OPTCFLAGS "-Ofast -ffast-math")
endif()

set(CMAKE_C_FLAG "${CMAKE_C_FLAG} -std=c99 -D_POSIX_C_SOURCE=200809L -Wall -Wno-maybe-uninitialized -pipe -I. ${OPTCFLAGS}")

if(LIBRARY_CONFIGURATION STREQUAL "SHARED")
    set(CMAKE_C_FLAG "${CMAKE_C_FLAG} -fPIC -fvisibility=hidden -DDST_SHARED -DDST_SHARED_EXPORTS")
    add_library(detex SHARED ${SOURCE_FILES})
else()
    add_library(detex ${SOURCE_FILES})
endif()

install(
    TARGETS detex
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
    FILES "detex.h"
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
